package com.wsoft.system.controller;

import com.wsoft.response.ResponseResult;
import com.wsoft.system.query.resourse.ResourceInsertQuery;
import com.wsoft.system.query.resourse.ResourceListQuery;
import com.wsoft.system.query.resourse.ResourceUpdateQuery;
import com.wsoft.system.query.resourse.category.CategoryInsertQuery;
import com.wsoft.system.query.resourse.category.CategoryListQuery;
import com.wsoft.system.query.resourse.category.CategoryUpdateQuery;
import com.wsoft.system.service.ISysResourceCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 资源分类表 前端控制器
 * @author juiet
 * @since 2024年11月18日 17:14:14
 */
@RestController
@Tag(name = "资源分类管理")
@RequestMapping("/sys/resource/category")
public class SysResourceCategoryController {
    @Resource
    private ISysResourceCategoryService resourcesCategoryService;
    @Operation(summary = "新增资源分类")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid CategoryInsertQuery query) {
        boolean b = resourcesCategoryService.insert(query);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "修改资源分类")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid CategoryUpdateQuery query) {
        boolean b = resourcesCategoryService.update(query);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "删除资源分类")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = resourcesCategoryService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "获取资源分类详情")
    @GetMapping("/get")
    public ResponseResult getCategory(@RequestParam("id") Long id) {
        return ResponseResult.success(resourcesCategoryService.getCategory(id));
    }
    @Operation(summary = "获取资源分类列表")
    @PostMapping("/list")
    public ResponseResult listCategory(@RequestBody @Valid CategoryListQuery query) {
        return ResponseResult.success((resourcesCategoryService.pageCategory(query)));
    }
}
